package com.prs.crm.action.taskmanager;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.taskmanager.LeadGroupSet;
import com.prs.crm.service.taskmanager.LeadGroupSetService;

public class LeadGroupSetAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private PaginationSupport pagination;
	private Integer[] ids;
	private LeadGroupSet leadGroupSet;
	private LeadGroupSetService leadGroupSetService;
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public LeadGroupSet getLeadGroupSet() {
		return leadGroupSet;
	}
	public void setLeadGroupSet(LeadGroupSet leadGroupSet) {
		this.leadGroupSet = leadGroupSet;
	}
	public LeadGroupSetService getLeadGroupSetService() {
		return leadGroupSetService;
	}
	public void setLeadGroupSetService(LeadGroupSetService leadGroupSetService) {
		this.leadGroupSetService = leadGroupSetService;
	}
	
	@Action("listLeadGroupSet")
	public String listLeadGroupSet(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(LeadGroupSet.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getLeadGroupSetService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	
	@Action("editLeadGroupSet")
	public String editLeadGroupSet(){
		if(ids!=null){
			this.leadGroupSet=this.getLeadGroupSetService().get(ids[0]);
		}
		return SUCCESS;
	}
	@Action(value = "saveLeadGroupSet", results = {
			@Result(name="success",type="redirect",location="listLeadGroupSet"),
			@Result(name="error",type="chain",location="editLeadGroupSet") })
	public String saveLeadGroupSet(){
		this.getLeadGroupSetService().save(leadGroupSet);
		return SUCCESS;
	}
	@Action(value = "removeLeadGroupSet", results = {
			@Result(name="success",type="redirect",location="listLeadGroupSet"),
			@Result(name="error",type="chain",location="listLeadGroupSet") })
	public String removeLeadGroupSet(){
		if(ids!=null){
			this.leadGroupSet=this.getLeadGroupSetService().get(ids[0]);
		}
		this.getLeadGroupSetService().batchRemove(ids);
		return SUCCESS;
	}
}
